<?php
namespace app\center\logic;
use app\center\validate\Copy as CopyValidate;

class CopyMyLogic extends BaseLogic {

    /**
     * 获取抄送给我查询条件
     * @param $openid
     * @param $from_openid
     * @param $source
     * @param $start_time
     * @return array
     */
    public function get_search_cm_maps($openid,$from_openid,$source,$start_time){
        $maps = [];
        $maps[] = ['copy_openid','=',$openid];
        $maps[] = ['status','=',1];

        if(!empty($from_openid)){
            $maps[] = ['from_openid','=',$from_openid];
        }

        if($source != -1){
            $maps[] = ['source','=',$source];
        }

        if(!empty($start_time)){
            $maps[] = ['c_time','like',$start_time . '%'];
        }
        return $maps;
    }

    /**
     * 检查处理抄送给我规则
     * @param $openid
     * @param $params
     * @return mixed
     */
    public function check_deal_cm_rule($openid,$params){
        $validate = new CopyValidate();
        $r = $validate->scene('edit')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }

        $maps = [];
        $maps[] = ['id','=',$params['copyid']];
        $maps[] = ['copy_openid','=',$openid];
        $maps[] = ['status','=',1];
        $c_detail = model('copy')->get_detail($maps);
        if(empty($c_detail)){
            return $this->get_response(0,'该抄送不存在');
        }

        $data['c_detail'] = $c_detail;
        return $this->get_response(1,'OK',$data);
    }
}